class Solution:
    def findKDistantIndices(self, nums: list, key: int, k: int) -> list:
        keyIndexes = []
        for i in range(len(nums)):
            num = nums[i]
            if num == key:
                keyIndexes.append(i)

        res = []
        s = set()
        for keyIndex in keyIndexes:
            for i in range(keyIndex - k, keyIndex+k+1):
                if i < 0:
                    continue
                if i >= len(nums):
                    continue
                if i not in s:
                    res.append(i)
                    s.add(i)
        return res
